#!/bin/bash
#
export JAVA_HOME={{jdk_base_path}}
export PATH=$JAVA_HOME/bin:$PATH

listenip={{ inventory_hostname }}
listenport={{ rocketmq_console_port }}
rocketmq_console_path={{ rocketmq_console_path }}
nameserver='{% for nameserver in groups.rocketmq_namesrv %}{{ nameserver }}:{{rocketmq_ns_port}}{% if not loop.last %};{% endif %}{% endfor %}'

function start(){
    cd ${rocketmq_console_path}
    nohup java -jar rocketmq-console.jar --server.port=${listenport} --rocketmq.config.namesrvAddr=${nameserver} &
}

function stop(){
    kill -9 `ps -ef|grep -v grep|grep rocketmq-console|awk '{print $2}'`
}

function restart(){
    stop;
    sleep 1
    start
}
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 2
        ;;
esac
